(function (exports) {

    var $ = null;

    var LearnWordLayer = cc.Layer.extend({

        onEnter: function () {
            cc.Layer.prototype.onEnter.call(this);
        },
        onCCSLoadFinish: function () {
            var that = this;
        },
        onExit: function () {
            cc.Layer.prototype.onExit.call(this);
        },
        ctor: function () {
            this._super();

            var that = this;

            loadCCSTo(res.LearnWordLayer_json, this, "Layer");
            $ = create$(this.getChildByName("Layer"));
            shipei($);

            TouchUtils.setOnclickListener($('top.close'), function (node) {
                that.removeFromParent();
            });

            playEffect('music_siji_1');

            this.initTableView();
        },

        //tableview
        initTableView: function () {
            var TableView = new cc.TableView(this, cc.size($('root.tableviewbg').getContentSize().width,
                $('root.tableviewbg').getContentSize().height - 30));
            TableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
            TableView.setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN);
            TableView.x = 0;
            TableView.y = 15;
            TableView.setDelegate(this);
            TableView.setBounceable(true);
            $('root.tableviewbg').addChild(TableView);
        },
        tableCellTouched: function (table, cell) {
            var idx = cell.getIdx();
        },
        tableCellSizeForIndex: function (table, idx) {
            return cc.size(600, 60);
        },
        tableCellAtIndex: function (table, idx) {
            var cell = table.dequeueCell();
            if(cell == null) {
                cell = new cc.TableViewCell();
            }
            var row0 = cell.getChildByName('cellrow');
            if(!row0) {
                row0 = ccs.load(res.LearnWordItem_json, "res/").node;
                row0.setName("cellrow");
                cell.addChild(row0);
            }
            var setData = function(ref){
                $("bg.word", ref).setString(sijiWord[idx][0]);
                $("bg.jieshi", ref).setString(sijiWord[idx][1]);
            };
            setData(row0);

            return cell;
        },
        numberOfCellsInTableView: function (table) {
            return sijiWord.length;
        },
    });
    exports.LearnWordLayer = LearnWordLayer;
})(window);
